package cn.iocoder.yudao.module.worker.service.reward.handler;

import cn.iocoder.yudao.module.trade.api.brokerage.BrokerageRecordApi;
import cn.iocoder.yudao.module.trade.api.brokerage.dto.BrokerageRecordCreateReqDTO;
import cn.iocoder.yudao.module.worker.dal.dataobject.reward.WorkerRewardDO;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class RewardBrokerageOrderHandler implements RewardOrderHandler {

    @Resource
    private BrokerageRecordApi brokerageRecordApi;

    @Override
    public void afterPayOrder(WorkerRewardDO order) {
        BrokerageRecordCreateReqDTO reqDTO = new BrokerageRecordCreateReqDTO();
        reqDTO.setId(order.getId());
        reqDTO.setUserId(order.getUserId());
        reqDTO.setWorkerUserId(order.getWorkerUserId());
        reqDTO.setPayMoney(order.getPayMoney());
        reqDTO.setGift(order.getGift());
        brokerageRecordApi.addRewardBrokerage(reqDTO);

        if(order.getWorkerClerkId() != null){
            brokerageRecordApi.calculateClerkBrokerage(order.getWorkerClerkId());
        }
    }

}
